package com.heima.article.controller.v1;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.heima.article.service.ApDataStatisticsService;
import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.wemedia.vos.WmNewsStatisticsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.Map;

@RestController
@RequestMapping("/api/v1/article")
public class ArticleStatisticsController {

    @Autowired
    private ApDataStatisticsService apDataStatisticsService;

    /**
     * 统计作者发布文章的点赞量 收藏量
     *
     * @param authorId 文章作者id
     * @return 返回结果
     */
    @GetMapping("/statistics")
    public ResponseResult<Map<String, Integer>> statistics(Integer authorId, Date beginDate, Date endDate) {
        Map<String, Integer> data = apDataStatisticsService.statistics(authorId, beginDate, endDate);
        return ResponseResult.okResult(data);
    }

    /**
     * 分页查询发布文章相关信息
     *
     * @param beginDate 开始时间
     * @param endDate   结束时间
     * @param page      页码
     * @param size      显示条数
     * @return 返回结果
     */
    @GetMapping("/articlePage")
    public ResponseResult<Page<WmNewsStatisticsVo>> articlePage(Date beginDate,
                                                                Date endDate,
                                                                Integer page,
                                                                Integer size,
                                                                Integer apUserId) {
        Page<WmNewsStatisticsVo> articlePage = apDataStatisticsService.articlePage(beginDate, endDate, page, size, apUserId);
        return ResponseResult.okResult(articlePage);
    }
}
